<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class System_model extends CI_Model {
	
	function __construct(){
        parent::__construct();
    }
    
    function borrow_repay(){
    	$today = time();
		$yestoday = strtotime(date('Y-m-d'));
		$nextday = strtotime(date('Y-m-d 23:59:59'));
 		$sql_result = "SELECT  id,user_id FROM zjy_borrow_repayment 
						 WHERE repayment_time>=$yestoday AND 
						 repayment_time<=$nextday  AND fstatus IN (0,2) ORDER BY id";
		
		/*$sql_result = "SELECT  id,user_id FROM zjy_borrow_repayment 
						 WHERE fstatus IN (0,2) ORDER BY id";*/
		
    	$query = $this->db->query($sql_result);
		return $query->result_array();
    }
    
	function lzborrow_repay(){
    	$today 		= time();
		$yestoday 	= strtotime(date('Y-m-d'));
		$nextday 	= strtotime(date('Y-m-d 23:59:59'));
 		$sql_result = " SELECT p1.id,p1.user_id 
 						FROM zjy_borrow_collection AS p1 LEFT JOIN zjy_borrow AS p2 ON p1.borrow_id=p2.id
						WHERE p1.repay_time>=$yestoday AND p1.repay_time<=$nextday AND 
						p1.fstatus=0 AND p2.fstatus=3 AND p2.ftype=4 ORDER BY p1.id";
 		
    	$query = $this->db->query($sql_result);
		return $query->result_array();
    }
    
    function slborrow_repay(){
    	$yestoday 	= strtotime(date('Y-m-d'));
		$nextday 	= strtotime(date('Y-m-d 23:59:59'));
 		$sql_result = " SELECT p1.id,p1.user_id 
 						FROM zjy_borrow_collection AS p1 LEFT JOIN zjy_borrow AS p2 ON p1.borrow_id=p2.id
						WHERE p1.repay_time<=$nextday AND 
						p1.fstatus=0 AND p2.fstatus=3 AND p2.ftype=6 ORDER BY p1.id";
 		
    	$query = $this->db->query($sql_result);
		return $query->result_array();
    }
    

	function liubiao(){
 		$sql_result = "SELECT id,user_id FROM zjy_borrow where fstatus=1 and verify_time+valid_time*24*60*60<".time();
    	$query = $this->db->query($sql_result);
		return $query->result_array();
    }
}    